<include file="common/header_lixin" title="实名认证" />
<style>
    .weui-label{
        color: #292828;
    }
</style>
<div class="page">
    <div class="page-hd">
        <div class="header bor-1px-b">
    <div class="header-left">
        <a href="javascript:history.go(-1)" class="left-arrow"></a>
    </div>
    <div class="header-title">实名认证</div>
    <div class="header-right">
        <a href="#"></a>
    </div>
</div>
    </div>

    <div class="page-bd">
        <!-- 页面内容-->
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">认证状态</label>
                </div>
                <div class="weui-cell__bd">
                    <p <if condition="$statusName eq 审核通过 "> class='fs28  text-green'</if>>{$statusName}</p>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">姓名</label>
                </div>
                <div class="weui-cell__bd">
<!--                    <p class="fs28">{$user['nickname']}</p>-->
                    <input class="weui-input" name="realName" value="{$user['nickname']}" >
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">身份证号码</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" name="IDCart"  value="{$info['IDCart']}" type="text"  placeholder="请输入身份证号码">
                    <!-- <p class="fs28">43251419684152144124412</p> -->
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">邮箱</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input phone_input" placeholder="请输入邮箱" name="email"  type="text">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">验证码</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input phone_input" placeholder="请输入验证码" name="email_code"  type="text" style="width: 50%">
                    <a href="javascript:void(0)" id="send" onclick="sendCode()" style="background: #F00;color: #fff;padding: 6px;border-radius: 20px;">获取验证码</a>
                </div>
            </div>
     <!--       <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">支付宝账号</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" name="ali" value="{$info['ali']}" type="text"  placeholder="请输入支付宝账号">
                    &lt;!&ndash; <p class="fs28">6235412514564125411</p> &ndash;&gt;
                </div>
            </div>
            <if condition="$info['status'] neq 1">

                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">二级密码</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" name="paypwd" type="password"  placeholder="请输入二级密码">
                    </div>
                </div>

            </if>-->
        </div>

        <div class="weui-btn-area">
            <empty name="$info">
                <a href="javascript:;" onclick="formSub()" class="weui-btn weui-btn_primary">提交</a>
            <else />
                <if condition="$info['status'] eq 2">
                    <a href="javascript:;" onclick="formSub()" class="weui-btn weui-btn_primary">提交</a>
                </if>
            </empty>
        </div>
    </div>
</div>
<script src="__PUBLIC__/assets_reg/js/jquery.cookie.js"></script>

<script>
    $(function() {
        FastClick.attach(document.body);
    });
    <if condition="$info['status'] eq 2">
        var msg = "{$info['admin_note']}";
        $.toptip(msg, 'error');
    </if>
    var ajax_status = false;
    //验证表单
    function formSub(){
        var realName = $('input[name="realName"]').val();
        var ali = $('input[name="ali"]').val();
        var paypwd = $('input[name="paypwd"]').val();
        var IDCart = $('input[name="IDCart"]').val();
        var reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
        if (reg.test(IDCart) == false) {
            $.toptip('请输入合法身份证信息', 'error');
            return ;
        }
        var email = $('input[name="email"]').val();
        var email_code = $('input[name="email_code"]').val();
        if (realName.length <= 0){
            $.toptip('请输入真实姓名', 'error');
            return ;
        }
        if (email.length <= 0){
            $.toptip('请输入邮箱', 'error');
            return ;
        }
        if (email_code.length <= 0){
            $.toptip('请输入验证码', 'error');
            return ;
        }

        if (ajax_status) {return ;}
        ajax_status = true;
        $.ajax({
            url : "/index.php/Acc/Index/applyReal",
            type:'post',
            dataType:'json',
            data:{'realName':realName, 'ali' : ali, 'paypwd':paypwd,'IDCart':IDCart, 'email':email, 'email_code':email_code},
            success:function(data){
                if (data.code == 1) {
                    $.toast.prototype.defaults.duration = 1200;
                    $.toast(data.msg, function() {
                       window.location.href="/Acc/Index/index";
                    });
                } else {
                    $.toptip(data.msg, 'error');
                    ajax_status = false;
                }
            },
            error:function(){
                $.toptip('网络异常，请稍后再试', 'error');
            }
        })
    }

    function sendCode() {
        var mail = $("input[name='email']").val();
        var myreg = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
        if(!myreg.test(mail)){
            $.toast("请输入正确的邮箱！", "cancel");
            return false;
        }
        v = getCookieValue("secondsremained");//获取cookie值
        if (v == null || v < 0) {
            var obj = $("#send");
            addCookie("secondsremained", 60, 60);//添加cookie记录,有效时间60s
            settime(obj);//开始倒计时
            $.ajax({
                method: 'POST',
                dataType: 'JSON',
                data: {
                    "email" : mail
                },
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                url: "{:U('Login/sendEmailCode')}",
                success: function (data) {
                    $.toast(data.msg, "success");
                },error: function (result) {
                    $.toast('请求错误', "cancel");

                }
            });
        }
    }

    //发送验证码时添加cookie
    function addCookie(name,value,expiresHours){
        //判断是否设置过期时间,0代表关闭浏览器时失效
        if(expiresHours>0){
            var date=new Date();
            date.setTime(date.getTime()+expiresHours*1000);
            $.cookie(name, escape(value), {expires: date});
        }else{
            $.cookie(name, escape(value));
        }
    }
    //修改cookie的值
    function editCookie(name,value,expiresHours){
        if(expiresHours>0){
            var date=new Date();
            date.setTime(date.getTime()+expiresHours*1000); //单位是毫秒
            $.cookie(name, escape(value), {expires: date});
        } else{
            $.cookie(name, escape(value));
        }
    }
    //根据名字获取cookie的值
    function getCookieValue(name){
        return $.cookie(name);
    }
    //加载页面时获取Cookie并判断
    $(document).ready(function(){
        var obj1 = $("#send");
        v = getCookieValue("secondsremained");//获取cookie值
        if(v>0){
            settime(obj1);//开始倒计时
        }
    });
    //定义倒计时变量
    var countdown;

    // 倒计时函数
    function settime(obj) { //发送验证码倒计时
        countdown=getCookieValue("secondsremained");
        if (countdown === "0") {
            obj.attr('disabled',false);
            //obj.removeattr("disabled");
            obj.text("获取验证码");
            obj.css("background","#f00");
            return;
        } else {
            obj.attr('disabled',true);
            obj.text("重新发送(" + countdown + ")");
            obj.css("background","#999");
            countdown--;
            editCookie("secondsremained",countdown,countdown+2);
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }

</script>
</body>
</html>
